export default {
    name: 'Userreport',
    components: {

    },
    data() {
        return {
            height: '600',
            currentPage: 1,
            pagesize: 5,
            total: 0,
            userreportData: [],
            multipleSelection: [],
            users: "",
            activeData:"",
            unactiveData:"",
            count:""
        }
    },
    computed: {
        offset: function () {
            return (this.currentPage - 1) * this.pagesize;
        }
    },
    watch: {

    },
    created() {
        this.users = JSON.parse(window.localStorage.getItem("userInfo"));
        this.initUserList();
        this.userreportEchart();
    },
    mounted() {

    },
    methods: {
        //获取用户列表
        initUserList() {
          this.$http.post('/userController/findList?limit=' + this.pagesize + '&offset=' + this.offset)
             .then((res) => {
                if (res.status == 200) {
                    this.userreportData = res.rows;
                    this.total = res.total;
                }
              }).catch((err) => {
                console.log(err);
           });
      },
      //用户统计
      userreportEchart(){
          this.$http.get("/userController/userStatistics?uId="+this.users.uId)
           .then((res) => {
             if(res.status == 200){
                this.activeData = res.data.activate;
                this.unactiveData = res.data.nonactivated;
                this.count = res.data.total;
             }
           }).catch((err) => {
              console.log(err);
        });
      },
      //导出功能
      outExcel() {
        //导出修正文件名--利用a标签
        this.$http.post('/userController/userExportRecordExport', this.qs.stringify({
            limit: this.pagesize,
            offset: this.offset,
            uId:this.users.uId
          }), {
            responseType: 'arraybuffer'
          })
          .then((res) => {
              const content = res;
              const blob = new Blob([content], {
                type: "application/vnd.ms-excel"
              })
              const fileName = '用户统计表.xls';
              if ('download' in document.createElement('a')) {
                //非IE下载
                const link = document.createElement('a');
                link.download = fileName;
                link.style.display = 'none';
                link.href = URL.createObjectURL(blob);
                document.body.appendChild(link);
                link.click();
                URL.revokeObjectURL(link.href); //释放URL对象
                document.body.removeChild(link);
                this.initUserList();
              } else {
                //IE10+下载
                navigator.msSaveBlob(blob, fileName);
              }
          })
          .catch((res) => {
            console.log(res)
          });
        },
        toggleSelection(rows) {
            if (rows) {
                rows.forEach(row => {
                    this.$refs.multipleTable.toggleSelection(row);
                });
            } else {
                this.$refs.multipleTable.clearSelection();
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        handleSizeChange(val) {
            this.pagesize = val;
            this.initUserList();
        },
        handleCurrentChange(val) {
            this.currentPage = val;
            this.initUserList();
        }
    },
}